<template>
    <header>
        <div class="l-content">
            <el-button @click="handleMenu" plain icon="el-icon-menu" size="mini"></el-button>
            <!-- <h3 style="color: #fff">首页</h3> -->
            <!-- 面包屑 -->
            <el-breadcrumb separator="/">
                <el-breadcrumb-item v-for="item in tags" :key="item.path" :to="{ path: item.path }">{{item.label}}</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="r-content">
            <el-dropdown trigger="click" size="mini">
                <span>
                    <img :src="userImg" class="user">
                </span>
                <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item>个人中心</el-dropdown-item>
                    <el-dropdown-item @click.native="logOut">退出</el-dropdown-item>
                </el-dropdown-menu>
            </el-dropdown>
        </div>
    </header>
</template>

<script>
    import { mapState, Store } from 'vuex'
    export default {
        name:'CommonHeader',
        data() {
            return {
                userImg:require('/src/assets/images/user.png')
            }
        },
        methods: {
            //侧边栏折叠回调
            handleMenu(){
                this.$store.commit('collapseMenu');
            },

            //登出功能
            logOut() {
                //清除token
                this.$store.commit('clearToken')
                this.$store.commit('clearMenu')
                //跳转回login
                this.$router.push("/login")
            }
        },
        computed: {
            ...mapState({
                //store中面包屑的数据注入
                tags: state => state.tab.tabsList
            })
        }
    }
</script>

<style lang="less" scoped>
    header {
        display: flex;
        height: 100%;
        justify-content: space-between;
        align-items: center;
    }
    .l-content {
        display: flex;
        align-items: center;
        .el-button {
            margin-right: 20px;
        }
    }
    .r-content {
        .user {
            width: 40px;
            height: 40px;
            border-radius: 50%;
        }
    }
</style>